using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The CityCodeTableManager class is responsible for managing BO.CityCodeTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class CityCodeTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all CityCodeTable objects in the database.
        /// </summary>
        /// <returns>A list with all CityCodeTable from the database when the database contains any, or null otherwise.</returns>
        //[DataObjectMethod(DataObjectMethodType.Select, true)]
        //public static CityCodeTableList GetList()
        //{
        //    return CityCodeTableDB.GetList();
        //}
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static CityCodeTableList GetList(Int32 DistinctCode, Int16 CountryCode)
        {
            return CityCodeTableDB.GetList(DistinctCode, CountryCode);
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static CityCodeTableList GetList()
        {
            return CityCodeTableDB.GetList();
        }


        /// <summary>
        /// Gets a single CityCodeTable from the database without its data.
        /// </summary>
        /// <param name="cityCode">The CityCode of the CityCodeTable in the database.</param>
        /// <returns>A CityCodeTable object when the CityCode exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static CityCodeTable GetItem(short cityCode)
        {
            return GetItem(cityCode, false);
        }

        /// <summary>
        /// Gets a single CityCodeTable from the database.
        /// </summary>
        /// <param name="cityCode">The CityCode of the CityCodeTable in the database.</param>
        /// <param name="getCityCodeTableRecords">Determines whether to load all associated CityCodeTable records as well.</param>
        /// <returns>
        /// A CityCodeTable object when the CityCode exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static CityCodeTable GetItem(short cityCode, bool getCityCodeTableRecords)
        {
            CityCodeTable myCityCodeTable = CityCodeTableDB.GetItem(cityCode);
            return myCityCodeTable;
        }

        /// <summary>
        /// Saves a CityCodeTable in the database.
        /// </summary>
        /// <param name="myCityCodeTable">The CityCodeTable instance to save.</param>
        /// <returns>The new CityCode if the CityCodeTable is new in the database or the existing CityCode when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static short Save(CityCodeTable myCityCodeTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                short cityCodeTableCityCode = CityCodeTableDB.Save(myCityCodeTable);

                //  Assign the CityCodeTable its new (or existing CityCode).
                myCityCodeTable.CityCode = cityCodeTableCityCode;

                myTransactionScope.Complete();

                return cityCodeTableCityCode;
            }
        }

        /// <summary>
        /// Deletes a CityCodeTable from the database.
        /// </summary>
        /// <param name="myCityCodeTable">The CityCodeTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(CityCodeTable myCityCodeTable)
        {
            return CityCodeTableDB.Delete(myCityCodeTable.CityCode);
        }

        #endregion

    }

}
